import Schema from 'async-validator';

import Form from './form';
import View from './view';
import { getValidate } from '../utils';

export const NAV_TYPE = {
  normal: {
    value: 'normal',
    label: '标准',
  },
  immersion: {
    value: 'immersion',
    label: '沉浸式',
  },
} as const;

export const DEFAULT_IMAGE =
  '';

export const TPL_TYPE = {
  normal: {
    value: 'normal',
    label: '标准样式',
    image: DEFAULT_IMAGE,
  },
  arc: {
    value: 'arc',
    label: '圆弧样式',
    image: DEFAULT_IMAGE,
  },
  roundedEdges: {
    value: 'roundedEdges',
    label: '圆角样式',
    image: DEFAULT_IMAGE,
  },
  sink: {
    value: 'sink',
    label: '导航色下沉',
    image: DEFAULT_IMAGE,
  },
} as const;

export const NAV_BG_TYPE = {
  normal: {
    value: 'normal',
    label: '默认',
  },
  custom: {
    value: 'custom',
    label: '自定义',
  },
} as const;

export const BG_TYPE = {
  color: {
    value: 'color',
    label: '单色',
  },
  gradient: {
    value: 'gradient',
    label: '渐变',
  },
  image: {
    value: 'image',
    label: '图片',
  },
} as const;

export const SCROLL_TYPE = {
  scroll: {
    value: 'scroll',
    label: '滚动',
  },
  fixed: {
    value: 'fixed',
    label: '不滚动',
  },
};

export const initialValues = {
  // 页面标题
  title: '首页',
  // 导航设置
  navType: NAV_TYPE.normal.value as keyof typeof NAV_TYPE,
  // 模板选择
  tplType: TPL_TYPE.normal.value as keyof typeof TPL_TYPE,
  // 顶部主题色类型
  navBgType: NAV_BG_TYPE.normal.value as keyof typeof NAV_BG_TYPE,
  // 具体色值
  navBgColor: '#ffffff',
  // 背景类型
  bgType: BG_TYPE.color.value as keyof typeof BG_TYPE,
  // 背景色值
  bgColor: '#F6F6F6',
  // 渐变色
  bgColorRange: ['#fff', '#fff'],
  // 背景图
  bgImage: '',
  // 是否可以滚动
  scrollType: SCROLL_TYPE.scroll.value,
} as const;

export const rules = {
  title: [
    {
      required: true,
      message: '标题不能为空',
    },
    {
      min: 2,
      message: '标题长度不能小于2',
    },
    {
      max: 10,
      message: '标题长度不能大于10',
    },
  ],
  navType: [
    {
      required: true,
      message: '导航设置不能为空',
    },
  ],
  tplType: [
    {
      required: true,
      message: '模板不能为空',
    },
  ],
  navBgType: [
    {
      required: true,
      message: '顶部主题设置不能为空',
    },
  ],
  bgType: [
    {
      required: true,
      message: '背景设置不能为空',
    },
  ],
  scrollType: [
    {
      required: true,
      message: '滚动设置不能为空',
    },
  ],
};

export type PageSettingValue = typeof initialValues;

export default {
  id: 'page',
  type: 'PageSetting',
  title: '页面设置',
  logo: '',
  initialValues,
  view: View,
  form: Form,
  limit: 10,
  validate: getValidate(rules),
};
